package com.txhy.certificatechain.ui.activity.pay;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.txhy.certificatechain.R;
import com.txhy.certificatechain.api.UrlAddress;
import com.txhy.certificatechain.model.bean.ElicenseBean;
import com.txhy.certificatechain.model.bean.ScannerResultBean;
import com.txhy.certificatechain.presenter.base.BasePresenter;
import com.txhy.certificatechain.ui.activity.base.BaseActivity;
import com.txhy.certificatechain.utils.GsonUtil;
import com.txhy.certificatechain.utils.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2014-2016, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * 文    件: ScannerResultActivity.java
 * 作    者: 侯建军
 * 版    权: 1.0.0
 * 描    述: 扫描结果页
 * 创建时间: 2018/9/21 11:34
 * 更新时间：2018/9/21 11:34
 * -----------------------------------------------------------------
 * 2018/9/21 11:34 : 创建 ScannerResultActivity.java (侯建军);
 * -----------------------------------------------------------------
 */
public class ScannerResultActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_name_1)
    TextView tv_name_1;
    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.tv_sex_1)
    TextView tv_sex_1;
    @BindView(R.id.tv_sex)
    TextView tv_sex;
    @BindView(R.id.tv_mingZu_1)
    TextView tv_mingZu_1;
    @BindView(R.id.tv_mingZu)
    TextView tv_mingZu;
    @BindView(R.id.tv_bor_1)
    TextView tv_bor_1;
    @BindView(R.id.tv_bor)
    TextView tv_bor;
    @BindView(R.id.tv_card_1)
    TextView tv_card_1;
    @BindView(R.id.tv_card)
    TextView tv_card;
    @BindView(R.id.tv_qianFa_1)
    TextView tv_qianFa_1;
    @BindView(R.id.tv_qianFa)
    TextView tv_qianFa;
    @BindView(R.id.tv_time_1)
    TextView tv_time_1;
    @BindView(R.id.tv_time)
    TextView tv_time;
    @BindView(R.id.tv_address_1)
    TextView tv_address_1;
    @BindView(R.id.tv_address)
    TextView tv_address;
    private String code;

    @BindView(R.id.ll_card)
    LinearLayout ll_card;

    @BindView(R.id.ll_add)
    LinearLayout ll_add;
    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_scanner_result;
    }

    @Override
    public void initView() {
        super.initView();
        tv_title.setText("验证结果");
        code = getIntent().getStringExtra("code");

        switch (getIntent().getIntExtra("type", 0)) {
            case 0:
                OkGo.<String>post(UrlAddress.GETECARDQR_URL)//
                        .tag(this)//
                        .params("code", code)
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(Response<String> response) {
                                if (GsonUtil.GsonGetStatus(response.body()) == 200) {
                                    ScannerResultBean bean = GsonUtil.GsonToBean(response.body(), ScannerResultBean.class);
                                    tv_name.setText(bean.getData().getUsername());
                                    tv_sex.setText(bean.getData().getSex());
                                    tv_mingZu.setText(bean.getData().getNation());
                                    tv_bor.setText(bean.getData().getBirthTime());
                                    tv_card.setText(bean.getData().getCardId());
                                    tv_qianFa.setText(bean.getData().getOffice());
                                    tv_time.setText(bean.getData().getValidTime());
                                    tv_address.setText(bean.getData().getAddr());
                                } else {
                                    ToastUtil.showLong(ScannerResultActivity.this, GsonUtil.GsonGetMsg(response.body()));
                                }
                            }

                            @Override
                            public void onError(Response<String> response) {
                                super.onError(response);
                                ToastUtil.showLong(ScannerResultActivity.this, "请求失败请检查网络");
                                finish();
                            }
                        });
                break;
            case 1:
                tv_name_1.setText("企业名称");
                tv_sex_1.setText("社会统一信用代码");
                tv_mingZu_1.setText("法人");
                tv_bor_1.setText("住所");
                tv_card_1.setText("企业类型");
                ll_card.setVisibility(View.GONE);
                tv_qianFa_1.setText("注册资本");
                tv_time_1.setText("经营范围");
                ll_add.setVisibility(View.GONE);
                OkGo.<String>post(UrlAddress.GETCONFIRM_URL)//
                        .tag(this)//
                        .params("code", code)
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(Response<String> response) {
                                if (GsonUtil.GsonGetStatus(response.body()) == 200) {
                                    ElicenseBean bean = GsonUtil.GsonToBean(response.body(), ElicenseBean.class);
                                    tv_name.setText(bean.getData().getName());
                                    tv_sex.setText(bean.getData().getAreaFlag());
                                    tv_mingZu.setText(bean.getData().getCorporation());
                                    tv_bor.setText(bean.getData().getAddr());
                                    tv_qianFa.setText(bean.getData().getFund()+"万元");
                                    tv_time.setText(bean.getData().getScope());
                                    tv_address.setText(bean.getData().getAddr());
                                } else {
                                    ToastUtil.showLong(ScannerResultActivity.this, GsonUtil.GsonGetMsg(response.body()));
                                }
                            }
                            @Override
                            public void onError(Response<String> response) {
                                super.onError(response);
                                ToastUtil.showLong(ScannerResultActivity.this, "请求失败请检查网络");
                                finish();
                            }
                        });
                break;
        }
    }

    @OnClick({R.id.im_left})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.im_left:
                finish();
                break;
        }
    }
}
